//#pragma comment(linker,"/STACK:16777216") /*16Mb*/
//#pragma comment(linker,"/STACK:33554432") /*32Mb*/
#define _CRT_SECURE_NO_DEPRECATE
#include<sstream>
#include<iostream>
#include<numeric>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<memory>
#include<string>
#include<vector>
#include<cctype>
#include<list>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
using namespace std;

typedef unsigned long long      ui64;
typedef long long               i64;
typedef	vector<int>             VI;
typedef	vector<bool>            VB;
typedef	vector<VI>              VVI;
typedef	vector<string>          VS;
typedef	pair<int,int>           PII;
typedef map<string,int>         MSI;
typedef set<int>                SI;
typedef set<string>             SS;
typedef map<int,int>            MII;
typedef	pair<double,double>     PDD;

#define PB                      push_back
#define MP                      make_pair
#define X                       first
#define Y                       second
#define FOR(i, a, b)            for(int i = (a); i < (b); ++i)
#define RFOR(i, a, b)           for(int i = (a) - 1; i >= (b); --i)
#define CLEAR(a, b)             memset(a, b, sizeof(a))
#define SZ(a)                   int((a).size())
#define ALL(a)                  (a).begin(), (a).end()
#define RALL(a)                 (a).rbegin(), (a).rend()
#define INF                     (2000000000)

#ifdef _DEBUG
#define eprintf(...) fprintf (stderr, __VA_ARGS__)
#else
#define eprintf(...) assert (true)
#endif

int main()
{
	int test;
	cin >> test;
	string s;
		getline(cin,s);
	FOR(tesss,0,test) {
		
		string s;
		getline(cin,s);
		stringstream sin;
		sin << s;
		VS words;
		while(sin >> s)
			words.PB(s);
		bool at_home =  ("home" == words[3]);
		int a = atoi(words[6].c_str());
		int b = atoi(words[10].c_str());
		
		/*
		int at_home = true;
		int a = 1;
		int b = 1;
		cin >> at_home >> a >> b;
		*/if( at_home ) {
			int res1 = b-a;
			if( res1 < b )
				res1 ++;
			res1 = max( 0, res1 );
			res1 = min( 30, res1 );
			int res2 = b+30-a;
			if( res2 > b )
				res2 --;
			res2 = max( 0, res2 );
			res2 = min( 30, res2 );
			cout << res1 << " " << res2 << endl;
			continue;
		}
		//away game

		int res1 = max(0,b-a);
		int res2 = b+30-a;
		res2 = min( 30, res2 );
		res2 = max( 0, res2 );
		cout << res1 << " " << res2 << endl;
		continue;
	}
    return 0;
}